package com.cos.lession54.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * @author: COS
 * @time: 2022/3/9 11:38
 * @description:
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class User {
    private int id;
//    @JsonIgnore 忽略
//    @JsonProperty("e_name")
    //serialize 忽略 name 设置转换后的json的key值
    @JSONField(name = "username",serialize = false)
    private String name;
    //format 格式化的设置   SerializerFeature.WriteNullStringAsEmpty 如果有null就写出空字符串,只能使用在字符串上
    @JSONField(serialzeFeatures = SerializerFeature.WriteNullStringAsEmpty)
    private String sex;
    private int age;
    //设置json转换的日期格式
//    @JsonFormat(pattern = "yyyy年MM月dd日")
    @JSONField(format = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")//springmvc接受参数,帮我们封装数据
    private Date bornDate;
}
